<template>
  <transition name="fadeScale">
    <div class="seeAdvice" v-show="ifSee">
      <div class="message" :style="{'backgroundColor':color}">
        <div class="O"></div>
        <div class="X" @click="endSeeAdvice">
          <i class="iconfont iconcuowu"></i>
        </div>
        <p v-if="!writeAdvice">{{username}}</p>
        <p v-if="writeAdvice">{{Myusername}}</p>
        <span v-if="!writeAdvice">{{content}}</span>
        <div v-if="writeAdvice">
          <textarea name id cols="30" rows="10" v-model="adviceContent" placeholder="分享给所有人..."></textarea>
          <button @click="addAdvice">添加</button>
        </div>
      </div>
    </div>
  </transition>
</template>

<script>
import Bus from "../../bus";
export default {
  created() {
    Bus.$on("startSeeAdvice", (msg) => {
      console.log(msg);
      this.color = msg.color;
      this.content = msg.advice;
      this.ifSee = true;
      this.username = msg.username
    });
  },
  mounted() {},
  data() {
    return {
      ifSee: false,
      color: "",
      content: "出BUG了",
      writeAdvice: false,
      adviceContent: "",
      username:""
    };
  },
  computed: {
    Myusername(){
      return this.$store.getters.user.username
    }
  },
  methods: {
    endSeeAdvice() {
      this.ifSee = false;
    },
    addAdvice() {
      if (this.adviceContent) {
        this.$axios
          .post("/advice/add", {
            username: this.$store.getters.user.username,
            content: this.adviceContent,
          })
          .then((res) => {
            if (res.data.error === -1) {
              this.$parent.getAllAdvice()
              this.$emit("addAdviceStatus","success")
            } else {
              this.$emit("addAdviceStatus","error")
            }
          });
      } else {
        this.$emit("noContent","warn")
      }
    },
  },
  beforeDestroy() {
    Bus.$off("startSeeAdvice");
  },
};
</script>

<style lang="less" scoped>
@import url("../../css/comment/animate.css");
.seeAdvice {
  position: absolute;
  top: 0;
  width: 100vw;
  height: 100vh;
  left: 0;
  z-index: 9;
  background-color: rgba(0, 0, 0, 0.5);
  .message {
    position: relative;
    margin: 100px auto 0;
    width: 70%;
    height: 70%;
    overflow: hidden;
    padding: 50px;
    .O {
      position: absolute;
      width: 20px;
      height: 20px;
      border-radius: 20px;
      background-color: #fff;
      top: 15px;
      left: 20px;
    }
    .X {
      position: absolute;
      width: 20px;
      height: 20px;
      top: 15px;
      right: 20px;
      z-index: 99;
      font-size: 20px;
      transition: all 0.4s;
      &:hover {
        transform: scale(1.3) rotate(180deg);

      }
    }
    p {
      padding: 40px 50px;
      font-size: 25px;
      font-weight: 100;
      transition: all 0.4s;
      &:hover {
        transform: scale(1.1);
        color: #fff;
      }
    }
    textarea {
      border-radius: 10px;
      box-sizing: border-box;
      font-size: 15px;
      resize: none;
      width: 100%;
      height: 350px;
      font-size: 18px;
      padding: 17px 20px;
    }
    button {
      outline: none;
      border: 1px solid #333;
      width: 90px;
      height: 30px;
      border-radius: 15px;
      transition: all 0.4s;
      margin-top: 15px;
      cursor: url("../../assets/img/cur/mais.png"), default;

      &:hover {
        background-color: black;
        color: blanchedalmond;
      }
    }
    span {
      color: black;
      padding: 50px;
      font-size: 18px;
      letter-spacing: 1px;
    }
  }
}
</style>